﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Device.Location;
using Microsoft.Phone.Controls.Maps;
using googlemaps;
using System.Windows.Media.Imaging;
using ClientMobile.SSVService;

namespace googlemaps.Pages
{
    public partial class Profile : PhoneApplicationPage
    { 
        Singleton s = Singleton.Instance;
        public Profile()
        {
           
            InitializeComponent();
            Singleton s = Singleton.Instance;
            image1.Source = new BitmapImage(new Uri(s.Chauff.Image, UriKind.RelativeOrAbsolute));
            textBlock1.Text = s.Chauff.Nom;
            textBlock2.Text = s.Chauff.Prenom;
            textBlockAdresse.Text = s.Chauff.Adresse;
            textBlocTEl.Text = s.Chauff.Tel;
            textBlockMail.Text = s.Chauff.Email;
            textBlockLogin.Text = s.Chauff.Login;
            textBox1.Text = s.Chauff.Adresse;
            textBox2.Text = s.Chauff.Tel;
            textBox3.Text = s.Chauff.Email;
            textBox4.Text = s.Chauff.Login;


        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            textBlock1.Visibility = Visibility.Collapsed;
            textBlock2.Visibility = Visibility.Collapsed;
            textBlockLogin.Visibility = Visibility.Collapsed;
            textBlockMail.Visibility = Visibility.Collapsed;
            textBlockAdresse.Visibility = Visibility.Collapsed;
            textBlocTEl.Visibility = Visibility.Collapsed;
            textBox1.Visibility =Visibility.Visible;
            textBox2.Visibility = Visibility.Visible;
            textBox3.Visibility = Visibility.Visible;
            textBox4.Visibility = Visibility.Visible;
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            Service1SoapClient ser = new Service1SoapClient();
            ser.ModifierChauffeurCompleted += new EventHandler<ModifierChauffeurCompletedEventArgs>(ser_ModifierChauffeurCompleted);
            ser.ModifierChauffeurAsync(textBlock1.Text, textBlock2.Text, textBlockAdresse.Text, textBlocTEl.Text, textBlockLogin.Text, s.Chauff.Password, s.Chauff.Image, textBlockMail.Text, s.Chauff.id_chauffeur);
        
            ser.ConsulterChauffeurCompleted += new EventHandler<ConsulterChauffeurCompletedEventArgs>(ser_ConsulterChauffeurCompleted);
            ser.ConsulterChauffeurAsync(s.Chauff.id_chauffeur);
        }

        void ser_ModifierChauffeurCompleted(object sender, ModifierChauffeurCompletedEventArgs e)
        {
            //MessageBox.Show("Modification effectuée");
        }

       
        void ser_ConsulterChauffeurCompleted(object sender, ConsulterChauffeurCompletedEventArgs e)
        {
             if (e.Result != null )
            {
                s.Chauff = e.Result;
                textBlockAdresse.Text = s.Chauff.Adresse;
                textBlockLogin.Text = s.Chauff.Login;
                textBlockMail.Text = s.Chauff.Email;
                textBlocTEl.Text = s.Chauff.Tel;
                MessageBox.Show("Modification effectuée");
                textBlock1.Visibility = Visibility.Visible;
                textBlock2.Visibility = Visibility.Visible;
                textBlockMail.Visibility = Visibility.Visible;
                textBlockLogin.Visibility = Visibility.Visible;
                textBlocTEl.Visibility = Visibility.Visible;
                textBlockAdresse.Visibility = Visibility.Visible;
                textBox1.Visibility = Visibility.Collapsed;
                textBox2.Visibility = Visibility.Collapsed;
                textBox3.Visibility = Visibility.Collapsed;
                textBox4.Visibility = Visibility.Collapsed;
            }
            else
            {
                MessageBox.Show("Impossible d'enregistrer");
            
            }
        }

      

       
    }
}